<?php

namespace App\Service;

use App\Context\UserInfoContext;
use App\Model\AdminUserAction;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Context\Context;

class AdminLogService {

    public function __construct(RequestInterface $request, $routerConfig) {
        $userInfoContext = Context::get(UserInfoContext::class);

        $adminUserAction = new AdminUserAction();
        $adminUserAction->action_name = $routerConfig['title'];
        $adminUserAction->uid = $userInfoContext->userInfo['id'];
        $adminUserAction->nickname = empty($userInfoContext->userInfo['nickname']) ? '' : $userInfoContext->userInfo['nickname'];
        $adminUserAction->add_time = time();
        $adminUserAction->url = $routerConfig['url'];
        $adminUserAction->data = json_encode($request->all());

        $adminUserAction->save();
    }

}